<template>
  <div>
    <!-- 另一种解决办法 给每个路由添加meta{num：0}属性 -->
    <!-- v-model="$route.meta.num" -->
    <van-tabbar v-model="active" active-color="red" inactive-color="#000" route>
      <van-tabbar-item to="/home" icon="home-o">首页</van-tabbar-item>
      <van-tabbar-item to="/topic" icon="label-o">专题</van-tabbar-item>
      <van-tabbar-item to="/category" icon="apps-o">分类</van-tabbar-item>
      <van-tabbar-item to="/cart" icon="cart-o">购物车</van-tabbar-item>
      <van-tabbar-item to="/user" icon="user-o">我的</van-tabbar-item>
    </van-tabbar>
  </div>
</template>
 
<script>
export default {
  name: "",
  data() {
    return {
      // active: 2,
    };
  },
  computed: {
    // 路由匹配active 第一钟方法，第二种方式：使用路由的meta元数据，每个meta添加num属性
    active: {
      get() {
        switch (this.$route.path) {
          case "/home":
            return 0;
            break;
          case "/topic":
            return 1;
            break;
          case "/category":
            return 2;
            break;
          case "/cart":
            return 3;
            break;
          case "/user":
            return 4;
            break;
          default:
            break;
        }
      },
      set() {},
    },
  },
};
</script>
 
<style>
</style>